<?php
namespace Admin\Controller;
use Common\Controller\AdminController;

class IndexController extends AdminController{

	public function index(){
		$data['news_num'] = M('news')->count();
		$data['classify_num'] = M('classify')->count();
		$data['message_num'] = M('message')->count();
		$data['admins_num'] = M('admins')->count();
		$this->assign('data', $data);
		$_db_p = C('DB_PREFIX');
		$list1 = M('news')->alias('n')->field('c.name,n.id,n.title,n.pid,n.times,n.view')
					->join("LEFT JOIN {$_db_p}classify c on n.pid = c.id")->limit(5)->order('times desc')->select();
		$this->assign('list1', $list1);
		$this->display();
	}

	public function login(){
		$list = $this->getList('*', 'admin_login_log', null, 'times desc', true);
		$this->assign('list', $list);
		$this->display();
	}

	public function config(){
		if(IS_POST){
			$file = CONF_PATH . 'info.php';
			if(is_writable($file)){
				$result = file_put_contents($file, "<?php \nreturn " . stripslashes(var_export($_POST, true)) . ";", LOCK_EX);
				if($result > 0){
					@unlink(RUNTIME_FILE);
					$this->returnResult(true);
				}
			}
			$this->returnResult(false);
		}else{
			$this->display();
		}
	}
}